/*
 * =====================================================================================
 *
 *       Filename:  tuple.cc
 *
 *    Description:  implementation of tuple functions
 *
 *        Version:  1.0
 *        Created:  07/29/09 12:05:24
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Gestrom Drawn (mn), zhcfreesea@gmail.com
 *        Company:  zhc
 *
 * =====================================================================================
 */


#include<iostream>
#include<string>

#include"tuple.h"

using namespace std;

EatManTuple::EatManTuple()
{
    _action = Action();
    _excitation = NONE;
    _state = FULL;
    _time = 0;
}
void EatManTuple::show_tuple(void)
{
//FIXME:use map instead of string array
    //string action_table[] = {"EATING", "SLEEPING"};
    string excitation_table[] = {"NONE", "HUNGER"};
    string state_table[] = {"FULL", "HUNGERY"};
    cout << "time is " << _time << endl;
    cout << "Gestorm is " << state_table[_state] << " and get an excitation of "
        << excitation_table[_excitation] << " and he is " << _action._get_current_action()
        << "ing" << endl;
}

void EatManTuple::update()
{
    //store current tuple in tmp_tuple
    EatManTuple tmp_tuple(*this);

    //for next time of action
    if(tmp_tuple._excitation == HUNGER && tmp_tuple._action == "sleep"){
        _action = "eat";
    }else if(tmp_tuple._excitation == NONE && tmp_tuple._action == "eat"){
        _action = "sleep";
    }else
        ;
    //for next time of excitation
    if(tmp_tuple._state == FULL){
        _excitation = NONE;
    }else if(tmp_tuple._state == HUNGRY){
        _excitation = HUNGER;
    }
    //for next time of state
    if(tmp_tuple._time % 9 == 1){
        _state = HUNGRY;
    }else if(tmp_tuple._action == "eat"){
        _state = FULL;
    }else{
        ;//keep state still
    }
    //for next time of time
    _time++;
}
